package com.itheima.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAspect {

    @Pointcut("execution(* com.itheima.service.Impl.AccountServiceImpl.*(..))")
    public void pt(){}

    @Around("pt()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {

        Long start = System.currentTimeMillis();


        for (int i = 0; i < 9999; i++) {
            joinPoint.proceed();
        }

        Object result = joinPoint.proceed();

        String name = joinPoint.getSignature().getName();

        Long end = System.currentTimeMillis();

        System.out.println(name + "方法的万次执行耗时为：" + (end - start) + "ms");

        return result;

    }
}
